import sys
sys.path.append('..')
import RSASocket as rsk
from threading import Thread,Lock
from talk import Talk
import ui.TalkWindow as tw
from PyQt5.QtWidgets import QApplication,QMainWindow

server1=('127.0.0.1',5001)
server2=('127.0.0.1',5000)

import colorama
from colorama import init,Fore,Back,Style
init(autoreset=True)

def show_recv(obj,lock):
	while True:
		obj.recv()
		if obj.recvedText:
			print('\033[1;34;40mopposite: %s\033[0m' %obj.recvedText)
			obj.recvedText = ''


def send(ATalk,ui):
	text = ui.textEdit.toPlainText()
	ui.textEdit.setPlainText('')
	print('\033[1;32;40mmyself: %s\033[0m' %text)
	ATalk.send(text)



if __name__=='__main__':
	lock = Lock()
	ATalk = Talk(server1=server1,server2=server2)
	t1 = Thread(target=show_recv,args=(ATalk,lock))
	t1.start()

	app = QApplication(sys.argv)
	MainWindow = QMainWindow()
	ui = tw.Ui_MainWindow()
	ui.setupUi(MainWindow)
	
	ui.pushButton.clicked.connect(lambda:send(ATalk,ui))

	MainWindow.show()
	sys.exit(app.exec_())








































